package com.flashextended.utils.graphics.symbols
{
	import flash.display.Sprite;
	
	public class SymbolsBuilder
	{
		public function SymbolsBuilder()
		{
		}
		
		public static function buildStar(target:Sprite, x:Number, y:Number, points:Number, innerRadius:Number, outerRadius:Number, angle:Number=0):void
		{
			
			var count:Number = Math.abs(points);
			if (count>2) {
				// init vars
				var step, halfStep, start, n, dx, dy;
				// calculate distance between points
				step = (Math.PI*2)/points;
				halfStep = step/2;
				// calculate starting angle in radians
				start = (angle/180)*Math.PI;
				target.graphics.beginFill(0x000000, 1);
				target.graphics.moveTo(x+(Math.cos(start)*outerRadius), y-(Math.sin(start)*outerRadius));
				// draw lines
				for (n=1; n<=count; n++) {
					dx = x+Math.cos(start+(step*n)-halfStep)*innerRadius;
					dy = y-Math.sin(start+(step*n)-halfStep)*innerRadius;
					target.graphics.lineTo(dx, dy);
					dx = x+Math.cos(start+(step*n))*outerRadius;
					dy = y-Math.sin(start+(step*n))*outerRadius;
					target.graphics.lineTo(dx, dy);
				}
			}
		}
		
		public static function buildBurst(target:Sprite, x:Number, y:Number,
			sides:Number, innerRadius:Number, outerRadius:Number, 
			angle:Number=0 ):void
		{
			if (sides>2) {
				// init vars
				var step, halfStep, qtrStep, start, n, dx, dy, cx, cy;
				// calculate length of sides
				step = (Math.PI*2)/sides;
				halfStep = step/2;
				qtrStep = step/4;
				// calculate starting angle in radians
				start = (angle/180)*Math.PI;
				target.graphics.beginFill(0x000000, 1);
				target.graphics.moveTo(x+(Math.cos(start)*outerRadius), y-(Math.sin(start)*outerRadius));
				// draw curves
				for (n=1; n<=sides; n++) {
					cx = x+Math.cos(start+(step*n)-(qtrStep*3))*(innerRadius/Math.cos(qtrStep));
					cy = y-Math.sin(start+(step*n)-(qtrStep*3))*(innerRadius/Math.cos(qtrStep));
					dx = x+Math.cos(start+(step*n)-halfStep)*innerRadius;
					dy = y-Math.sin(start+(step*n)-halfStep)*innerRadius;
					target.graphics.curveTo(cx, cy, dx, dy);
					cx = x+Math.cos(start+(step*n)-qtrStep)*(innerRadius/Math.cos(qtrStep));
					cy = y-Math.sin(start+(step*n)-qtrStep)*(innerRadius/Math.cos(qtrStep));
					dx = x+Math.cos(start+(step*n))*outerRadius;
					dy = y-Math.sin(start+(step*n))*outerRadius;
					target.graphics.curveTo(cx, cy, dx, dy);
				}
			}
		}				

	}
}